package reflect;

import reflect.annotation.AutoRunClass;
import reflect.annotation.AutoRunMethod;

import java.lang.reflect.Method;
import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个类名：");
        String className = sc.nextLine();

        Class<?> cls = Class.forName(className);
        if (cls.isAnnotationPresent(AutoRunClass.class)) {
            Object obj = cls.newInstance();
            Method[] methods = cls.getDeclaredMethods();
            for (Method method : methods) {
                if (method.isAnnotationPresent(AutoRunMethod.class)){
                    System.out.println(method.getName());
                    method.invoke(obj);
                }
            }
        }else {
            System.out.println("该类没有被AutoRunClass注解修饰");
        }
    }
}
